package com.wisemoresystem.seal.action.seal.destroy;

import java.util.List;
import java.util.Map;

import org.ne.framework.data.util.ChkTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.wisemoresystem.seal.base.action.ProjBaseAction;
import com.wisemoresystem.seal.base.tip.Tip;
import com.wisemoresystem.seal.model.t_seal;
import com.wisemoresystem.seal.model.t_seal_destroy_verify;
import com.wisemoresystem.seal.model.t_seal_new;
import com.wisemoresystem.seal.model.t_seal_type_config;
import com.wisemoresystem.seal.service.SealDestroyService;
import com.wisemoresystem.seal.web.WebTools;

/**
 * 印章销毁 复核
 * 
 * @author hxj
 *
 */
@Controller("ixSealDestroyReview")
@Scope("prototype")
@RequestMapping("/ix/seal/destroy/review")
public class SealDestroyReviewAction extends ProjBaseAction {

	@Autowired
	private SealDestroyService service;

	// t_seal flag_stop=上缴停用
	@RequestMapping("/list")
	/**
	 * 印章销毁复核列表
	 * @param srh_name
	 * @return
	 */
	public ModelAndView list(String srh_name) {

		List<Map<String, Object>> list = service.selectSealDestroyReviewList(
				WebTools.getCurrentBankId(), srh_name, page);

		ModelAndView mv = new ModelAndView("/jsp/seal/destroy/review/list");
		mv.addObject("list", list);
		return mv;
	}

	// 转到复核页面
	/**
	 * 转到复核页面
	 * 
	 * @param v_id
	 *            复核id
	 * @return
	 */
	@RequestMapping("/verify_form")
	public ModelAndView verify_form(String v_id) {

		t_seal_destroy_verify verify = service.findObjById(v_id,
				t_seal_destroy_verify.class);
		System.err.println(verify);
		t_seal seal = service.findObjById(verify.getSeal_id(), t_seal.class);

		ModelAndView mv = new ModelAndView(
				"/jsp/seal/destroy/review/verify_form");
		mv.addObject("seal", seal);
		if (ChkTools.isNotNull(seal.getSeal_new_id())) {
			t_seal_new mac = service.findObjById(seal.getSeal_new_id(),
					t_seal_new.class);
			if (ChkTools.isNotNull(mac.getSeal_type_config_id())) {
				t_seal_type_config ma = service.findObjById(
						mac.getSeal_type_config_id(), t_seal_type_config.class);
				mv.addObject("ma", ma);
			}
			mv.addObject("mac", mac);
		}
		mv.addObject("v_id", v_id);
		return mv;
	}

	// 复核
	/**
	 * 复核
	 * 
	 * @param v_id
	 *            复核id
	 * @param verify
	 *            复核信息
	 * @return
	 */
	@RequestMapping("/verify")
	public ModelAndView verify(String v_id, t_seal_destroy_verify verify) {

		if (service.review(v_id, verify)) {
			super.setTipMsg("申请复核成功!", Tip.Type.success);
			logT.logH("印章销毁复核", t_seal_destroy_verify.class, v_id);
		} else {
			super.setTipMsg("申请复核失败!", Tip.Type.error);
		}

		ModelAndView mv = new ModelAndView("redirect:list.htm");
		return mv;
	}
}
